/**
 * 
 */
package com.hurr.assembly;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;

import com.hurr.assembler.Assembler;
import com.hurr.bo.Bank;
import com.hurr.bo.Inversion;
import com.hurr.dto.BankDto;
import com.hurr.dto.InversionDto;

/**
 * @author Fernando Perelli
 *
 */
public class BankAssembly {

	@SuppressWarnings("unchecked")
	public BankDto toDto(Bank bank) throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		BankDto bankDto = new BankDto();
		bankDto.setId(bank.getId());
		bankDto.setName(bank.getName());
		bankDto.setInversions((Collection<InversionDto>) Assembler.toDtos(bank.getInversions()));
		return bankDto;
	}
	
	@SuppressWarnings("unchecked")
	public Bank toModel(BankDto bankDto) throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException{
		Bank bank = new Bank();
		bank.setId(bankDto.getId());
		bank.setName(bankDto.getName());
		bank.setInversions((Collection<Inversion>) Assembler.toModels(bankDto.getInversions()));
		return bank;
	}

	public Collection<BankDto> toDtos(Collection<Bank> banks) throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
		Collection<BankDto> bankDtos = new ArrayList<BankDto>();
		for (Bank bank : banks) {
			BankDto bankDto = (BankDto) Assembler.toDto(bank);
			bankDtos.add(bankDto);
		}
		return bankDtos;
	}
	
	public Collection<Bank> toModels(Collection<BankDto> bankDtos) throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
		Collection<Bank> banks = new ArrayList<Bank>();
		
		for (BankDto bankDto : bankDtos) {
			Bank bank= (Bank) Assembler.toModel(bankDto);
			banks.add(bank);
		}
		return banks;
		
	} 
	
}
